import { Injectable } from '@nestjs/common'
import { CreateCalendarDto } from './dto/create-calendar.dto'
import { UpdateCalendarDto } from './dto/update-calendar.dto'
import { Equal, Repository, Not, IsNull, Between } from 'typeorm'
import { InjectRepository } from '@nestjs/typeorm'
import { Calendar } from './entities/calendar.entity'
import { CalendarTypeEnum } from 'src/types/calendar'
import { Staff } from '../staff/entities/staff.entity'
@Injectable()
export class CalendarService {
  constructor(
    @InjectRepository(Calendar)
    private readonly calendar: Repository<Calendar>,
    @InjectRepository(Staff)
    private readonly staff: Repository<Staff>
  ) {}
  async create(createCalendarDto: CreateCalendarDto) {
    const calendar = new Calendar()
    const staff = await this.staff.findOne({
      where: { id: createCalendarDto.staffId }
    })
    calendar.title = createCalendarDto.title
    calendar.startTime = createCalendarDto.startTime
    calendar.endTime = createCalendarDto.endTime
    calendar.remindTime = createCalendarDto.remindTime
    calendar.address = createCalendarDto.address
    calendar.type = createCalendarDto.type
    calendar.remark = createCalendarDto.remark
    calendar.staff = staff
    return this.calendar.save(calendar)
  }

  async findAll(id: number) {
    const data = await this.calendar.find({
      where: {
        staff: { id }
      },
      relations: ['staff']
    })
    return data
  }

  update(id: number, updateCalendarDto: UpdateCalendarDto) {
    return this.calendar.update(id, updateCalendarDto)
  }

  remove(ids: number[]) {
    return this.calendar.softDelete(ids)
  }

  thoroughRemove(ids: number[]) {
    return this.calendar.delete(ids)
  }
}
